<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script
	src="<c:url value='/js/jquery.ui.widget.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script
	src="<c:url value='/js/jquery.fileupload.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script
	src="<c:url value='/js/server/rqfCommon.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#detailPan {
	width: 100%;
	height: 100%;
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.deepDark {
	background-color: #CCC488;
}

.normalDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.file {
	position: relative;
	display: inline-block;
	background: #1e519f;
	/*border: 1px solid #99D3F5;*/
	border-radius: 4px;
	/* padding: 4px 12px; */
	overflow: hidden;
	color: #1E88C7;
	text-decoration: none;
	text-indent: 0;
	line-height: 20px;
	cursor: pointer !important;
}

.file input {
	position: absolute;
	font-size: 100px;
	right: 0;
	top: 0;
	opacity: 0;
	cursor: pointer;
}

.file:hover {
	background: #ccc;
	text-decoration: none;
}

.import_style {
	width: 100%;
	height: 140px;
}

#importBtn {
	width: 75px;
	height: 20px;
	color: white;
	text-align: center;
	margin-left: 5px;
	margin-right: auto;
	margin-top: 0px;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">
	var radioValue = [ {
		id : 1,
		text : "在职"
	}, {
		id : 0,
		text : "已离职"
	} ];
	var sexData = [ {
		id : 1,
		text : "男"
	}, {
		id : 0,
		text : "女"
	} ];
	var natureData = [ {
		id : 1,
		text : "长期"
	}, {
		id : 0,
		text : "短期"
	} ];
</script>

</head>
<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="300px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a><a
					class="mini-button" id="addTypeBtn" iconCls="icon-add" plain="true"
					onclick="addType">添加分类</a><a class="mini-button" id="deleteTypeBtn"
					iconCls="icon-remove" plain="true" onclick="deleteType">删除分类</a>来源类型：<span
					class="nameTitle">未选择</span></td>
				<td><a width="100px"></a> &nbsp;&nbsp;<span id="separatorId2"
					class="separator"> <a class="mini-button" id="addBtn"
						iconCls="icon-add" plain="true" onclick="add">新增来源</a><a
						class="mini-button" id="deleteBtn" iconCls="icon-remove"
						plain="true" onclick="deletes">删除来源</a>
				</span></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px;">
				<div class="mini-fit">
					<div class="mini-splitter" style="width: 100%; height: 100%;">
						<div size="320px" showCollapseButton="true">
							<div id="datagrid1" class="mini-datagrid gridFull"
								style="height: 100%; width: 100%;" showTreeIcon="true"
								borderStyle="border:1;" showPager="false"
								ondrawcell="ondatagridDrawCell" onrowclick="orgSelect"
								resultAsTree="false" expandOnLoad="true" showPageInfo="false"
								showFilterRow="true">
								<div property="columns">
									<div type="checkcolumn" field="Action" width="70px"
										headerAlign="center" align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch()">清除
										</a>
									</div>
									<div name="SourceType" field="SourceType" width="100%"
										headerAlign="center" align="left" allowSort="true">
										企业名称<input id="orgFilter" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect" emptyText="筛选..."
											onenter="onselect_1" />
									</div>
								</div>
							</div>
						</div>
						<div showCollapseButton="true">
							<div id="datagrid2" class="mini-datagrid gridFull"
								borderStyle="border:1;" showReloadButton="true" pagesize="100"
								sizeList="[20,50,100,200]" allowCellWrap="true"
								allowHeaderWrap="true" idField="No" multiSelect="true"
								showPager="true" allowAlternating="true"
								ondrawcell="ondatagrid1DrawCell_2"
								onrowdblclick="gridRowDbClick_2"
								style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
								collapseGroupOnLoad="false" showColumnsMenu="true"
								showFilterRow="true" onshowrowdetail="onShowRowDetail">
								<div property="columns">
									<div type="indexcolumn" width="40px"></div>
									<div type="checkcolumn" width="40px" align="center"></div>
									<div field="Action" width="70px" headerAlign="center"
										align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch_2">清除
										</a>
									</div>
									<div field="CardID" width="200px" headerAlign="center"
										align="left" allowSort="true">
										身份证号<input id="filter1" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="UserName" width="80px" headerAlign="center"
										align="left" allowSort="true">
										姓名<input id="filter2" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="Sex" width="60px" headerAlign="center"
										align="center" allowSort="true">
										性别<input id="filter3" property="filter" class="mini-combobox"
											style="width: 100%;" data="sexData"
											onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div name="emptyCol" width='100%' headerAlign="center"
										align="center" cellStyle="padding:0;"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="detailPan" class="subPageFrame" frameborder="0">
				</iframe>
			</div>
		</div>
	</div>


	<script type="text/javascript">
		mini.parse();

		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var userLevel = '${userLevel}';
		var userCard = '${userCard}';
		var type = 1;

		var filterHelper = gridFilter();
		var filterHelper2 = gridFilter();

		var typeBtn = mini.get("typeBtn");
		var datagrid1 = mini.get("datagrid1");
		var datagrid2 = mini.get("datagrid2");
		var splitpan = mini.get("splitterPan");
		var orgFilter = mini.get("orgFilter");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");
		var filter5 = mini.get("filter5");
		var typeId = null;
		var sourceType = null;
		var state = 1;

		var starting = mini.get("starting");
		var ending = mini.get("ending");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		function onselect_1() {
			var filterValue0 = orgFilter.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("SourceType",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function onselect_2() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			filterHelper2.clearFilterData();

			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("CardID",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("UserName",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("Sex",
						filterValue3, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			loadGrid2(typeId);

		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/source/type' />";
			datagrid1.load(url);
			datagrid1.load(postData, function() {
				var row = datagrid1.getRow(0);
				if (row) {
					datagrid1.setSelected(row);
					typeId = row.Id;
					sourceType = row.SourceType;
					$('.nameTitle').html(sourceType);
					onselect_2();
				}
			});
		}
		function orgSelect() {
			var row = datagrid1.getSelected();
			if (!row) {
				return;
			}
			typeId = row.Id;
			if (!typeId) {
				mini.alert('数据有误 ，请联系管理员处理！');
				return;
			}
			sourceType = row.SourceType;
			$('.nameTitle').html(sourceType);
			onselect_2();
		}
		function loadGrid2(typeId) {
			var filterData = filterHelper2.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/source/list/' />" + typeId ;
			datagrid2.load(url);
			datagrid2.load(postData);
		}
		function removeSearch() {
			orgFilter.setValue();
			orgFilter.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}
		function removeSearch_2() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filterHelper2.clearFilterData();
			loadGrid2(typeId);
		}
		function ondatagridDrawCell(e) {
			var field = e.field;
			var row = e.row;
		}
		function ondatagrid1DrawCell_2(e) {
			var row = e.row;
			var field = e.field;
			if (field == "Action") {
				var id = row.CardID;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:update(\''
						+ id + '\')">[详细]</a>';
			}

			if (field == "Sex") {
				var value = e.value;
				if (typeof value == 'number') {
					e.cellHtml = (value == 1) ? '男' : '女';
				}
			}
		}

		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#addTypeBtn').show();
			$("#deleteTypeBtn").show();
			$("#addBtn").show();
			$("#deleteBtn").show();
			$("#separatorId2").show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#addTypeBtn').hide();
			$("#deleteTypeBtn").hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
			$('#separatorId2').hide();
		}
		function status3Show() {
			$('#rebackBtn').show();
			$('#addTypeBtn').hide();
			$("#deleteTypeBtn").hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
			$('#separatorId2').hide();
		}
		function reloadList1() {
			datagrid1.reload();
		}
		function reloadList() {
			datagrid2.reload();
		}

		function FormatDate(strTime) {
			var date = new Date(strTime);
			return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
					+ date.getDate() + " " + date.getHours() + ":"
					+ date.getMinutes();
		}

		function add() {
			var row = datagrid1.getSelected();
			if (!row) {
				mini.alert('请选择来源类型！');
				return;
			}
			var typeId = row.Id;
			if (!typeId) {
				mini.alert('来源有误，请联系管理员处理！');
				return;
			}
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/source/add/" />' + typeId);
		}
		function gridRowDbClick_2(e) {
			var row = e.row;
			if (!row)
				return;
			update(row.CardID);
		}
		function update(id) {
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/source/edit/" />' + id);
		}

		//入职与离职
		function employ(type) {
			var rows = datagrid2.getSelecteds();
			var text = null;
			if (type == 1) {
				text = "重新入职到本公司"
			} else if (type == 0) {
				text = "从本公司离职"
			} else {
				return;
			}

			if (rows.length <= 0) {
				mini.alert("请选择需要" + text + "的人员！");
				return;
			}
			mini.confirm("确定将所选择人员" + text + "？", "确定？", function(action) {
				if (action == "ok") {
					var id = "";
					for (var i = 0; i < rows.length; i++) {
						if (id == "") {
							id = rows[i].CardID;
						} else {
							id += "," + rows[i].CardID;
						}
					}
					var url = rootPath + "/user/employ/" + type;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							"employIds" : id
						},
						success : function(data) {
							if (data) {
								top.commonTools.showTip("操作成功！", 1);
								datagrid2.reload();
							} else {
								top.commonTools.showTip("操作失败！", 2);
								datagrid2.reload();
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误！", 2);
						}

					});
				}
			});
		}
		function addType(){
			var url = "<c:url value='/source/type/add' />";
			mini.open({
				url : url,
				title : "添加来源分类",
				width : 400,
				height : 300,
				onload : function() {
				},
				ondestroy : function(action) {
					if(action == 'ok'){
						reloadList1();
					}
				}
			});
		}
		function deleteType() {
			var row = datagrid1.getSelected();
			if (!row) {
				mini.alert("请选择需要删除的类型！");
				return;
			}
			var id = row.Id;
			if (!id) {
				mini.alert("数据有误！");
				return;
			}
			mini.confirm("确定删除所选类型？", "确定？", function(action) {
				if (action == "ok") {
					var url = rootPath + "/source/type/delete" ;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							"ids" : id
						},
						success : function(data) {
							if (data) {
								top.commonTools.showTip("操作成功！", 1);
								reloadList1();
							} else {
								top.commonTools.showTip("操作失败！", 2);
								reloadList1();
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误！", 2);
						}

					});
				}
			});
		}
	</script>
</body>
</html>